#include "HttpServer.hpp"

void Login(HttpRequest& req,HttpResponse& resp)
{
    //根据req,动态构建resp
    LOG(LogLevel::DEBUG) << "进入登录模块" << req.Path() << ", " << req.Args();
    std::string req_args = req.Args();
    //1.解析参数

    //2.访问数据库

    //3.登录成功
    // std::string body = "<html><body><p>Login Success!</p></body></html>";
    std::string body = req.GetContent("wwwroot/success.html");
    resp.SetCode(200);
    resp.SetHeader("Content-Length",std::to_string(body.size()));
    resp.SetHeader("Content-Type","text/html");
    resp.SetHeader("Set-Cookie","username=zhangsan;passwd=1111111111;");
    resp.SetBody(body);

}
void Register(HttpRequest& req,HttpResponse& resp)
{
    LOG(LogLevel::DEBUG) << "进入注册模块" << req.Path() << ", " << req.Args();
}

int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }
    auto httpserver = std::make_unique<HttpServer>(std::stoi(argv[1]));
    //服务器的登录功能
    httpserver->Resigster("/login",Login);
    httpserver->Resigster("/Register",Register);
    httpserver->Start();
    return 0;
}
